package com.jz.cash.client.service;

import com.jz.cash.client.entity.FunctionConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class PermService {

    @Autowired
    private FunctionConfigService functionConfigService;

    public Set<String> getPermsByUserId(Long id) {
        Set<String> perms = new HashSet<>();

        List<FunctionConfig> allFuncs =  functionConfigService.findAllFuncsByUserId(id);
        if (!CollectionUtils.isEmpty(allFuncs)) {
            perms = allFuncs.stream().map(f -> f.getName()).collect(Collectors.toSet());
        }
        return perms;
    }
}
